From 574d42327191bc1d38e2ac30b0cd20180bedbd44 Mon Sep 17 00:00:00 2001 From: robertl Date: Wed, 8 Jan 2003 15:58:23 +0000 Subject: [PATCH] Fix up timezones on GPX input. Combination of Park, Fouts, and myself. --- gpsbabel/gpx.c | 14 +------------- gpsbabel/util.c | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/gpsbabel/gpx.c b/gpsbabel/gpx.c index b73c84302..98af66274 100644 --- a/gpsbabel/gpx.c +++ b/gpsbabel/gpx.c @@ -388,19 +388,7 @@ gpx_end(void *data, const char *el) tm.tm_mon -= 1; tm.tm_year -= 1900; tm.tm_isdst = 1; - wpt_tmp->creation_time = mktime(&tm); -#if 0 - /* mktime assumes local time, and Z is gmtime */ - /* localtime will initialize timezone and daylight */ - /* 12/31/02 - RJL - unfortunately, this fix relies - * on non-ANSI extensions, so I've turned this off - * and reverted to the old way. - */ - localtime( &wpt_tmp->creation_time ); - wpt_tmp->creation_time -= timezone - (daylight?3600:0); -#else - wpt_tmp->creation_time = mktime(&tm); -#endif + wpt_tmp->creation_time = mktime(&tm) + get_tz_offset(); } if (in_wpt && in_gs_type && !in_gs_log) { wpt_tmp->gc_data.type = gs_mktype(cdatastr); diff --git a/gpsbabel/util.c b/gpsbabel/util.c index c74a6084a..3e64373c8 100644 --- a/gpsbabel/util.c +++ b/gpsbabel/util.c @@ -106,6 +106,7 @@ fprintdms(FILE *file, const coord *c, int is_lat) } fprintf(file, "%c%f\t", d, fabs(c->degrees)); } + void fatal(const char *fmt, ...) { @@ -195,3 +196,20 @@ si_round( double d ) return (signed int)(d+0.5); } } + +/* + * Return a time_t suitable for adding to a time_t that is in GMT to + * make it a local time. + */ +signed int +get_tz_offset(void) +{ + time_t now = time(0); + time_t later = mktime(gmtime(&now)); + + if (later == -1) { + return 0; + } else { + return (signed int) difftime(now, later); + } +} -- 2.30.2